//document.getElementById("vedio_play").setAttribute("src", "http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4");
let time = new Date();
$("#video_play").hide();
$("button").hide();
// $("#thumbnail").hide();
function upimg(){
    var image = document.querySelector("img");
    let files = document.getElementById('upImageFile').files[0];
    var file_name_time = localStorage.getItem("user");
    const reader = new FileReader();
    reader.readAsDataURL(files)
        reader.onload = () => {
          imgStr = reader.result.replace(/^data:image\/\w+;base64,/, "");

          console.log(imgStr)
          $.ajax({
            type: 'POST',
            url: "http://127.0.0.1:80/upimg/",
            headers: {
              "Content-type": "application/x-www-form-urlencoded",
              "token": localStorage.getItem("token")
            },
            data: { 
              base64: imgStr, 
              name: file_name_time 
            },
            success: function(response) {
              // Handle the response here
              alert("上传成功")

              $("#video_play").show();
              $("button").show();
              
              $("#video_play").attr("src","http://127.0.0.1/video/"+ localStorage.getItem("user") +".mp4/")
            },
            error: function(xhr, exception){
                if(xhr.status=="403"){
                    alert("token出错")
                }
            }
          });



          // // 创建XMLHttpRequest对象
          // xmlhttp = new XMLHttpRequest();
          // xmlhttp.open("POST","http://127.0.0.1:80/upimg/",false);
          // //这行代码很关键，用来把字符串类型的参数序列化成Form Data
          // xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
          // xmlhttp.setRequestHeader("token", localStorage.getItem("token"));
	      

          // // 设置回调函数
          // xmlhttp.onreadystatechange = function () {
          //   if(this.status == 200){
          //     alert("上传成功")
          //   }
          // }
          // // xmlhttp.send("base64="+imgStr+ "file_name="+file_name_time)
          // var fd = new FormData();
          // fd.append("base64", imgStr);
          // fd.append("file_name", file_name_time)
          // // xmlhttp.send(JSON.stringify({"base64":imgStr, "file_name":file_name_time}));
          // xmlhttp.send(fd);

        }
}
function all_play(){

  $("video")[0].play();
  $("video")[1].play();
}